<script>
import {getCourseListNew} from "@/api/http";

export default {
  name: "courseCom",
  data() {
    return {
      courseParams: {
        type: '',
        pageNum: 2,
        pageSize: 5
      },
      courseList: [],
      msg:'子组件插槽数据'
    }
  },
  props: {
    // courseType: String
    courseType: {
      type: String,
      default: 'free'
    }
  },
  methods: {
    getCourseList(data) {
      getCourseListNew(data).then(res => {
        console.log(res)
        this.courseList = res.rows
      })
    }
  },
  created() {
    console.log(this.courseType, 'courseType')
    this.courseParams.type = this.courseType
    this.getCourseList(this.courseParams)
  }
}
</script>

<template>
  <div>
    <!--  插槽：普通（默认）插槽、具名插槽、作用域插槽  -->
    <!--  具名插槽：name:插槽名  -->
    <slot name="title"></slot>
    <!--    课程组件-->
    <div class="course">
      <div class="course-item" v-for="item in courseList" :key="item.courseId">
        <!--       <router-link :to="{path:'/pageB',query:{id:item.courseId}}">-->
        <router-link :to="{name:'pageB',params:{id:item.courseId}}">
          <img :src="item.bannerFileUrl" alt="">
          <p>{{ item.courseTitle }}</p>
          <!--        <p>免费</p>-->
          <p v-if="item.isFree==='1'">免费</p>
          <p v-else-if="item.isDiscount==='1'">{{ item.discountPrice }}
            <del>{{ item.coursePrice }}</del>
          </p>
          <p v-else>{{ item.coursePrice }}</p>
        </router-link>
      </div>
    </div>
    <slot name="footer"></slot>
    <slot name="sonSlot" :sonData="msg"></slot>
  </div>
</template>

<style scoped lang="less">
.course {
  display: flex;
  width: 1200px;
  justify-content: space-around;

  &-item {
    width: 18%;

    img {
      width: 100%;
    }
  }
}
</style>